package com.xjy.web.controller.system.basics;

import java.util.List;
import java.util.Arrays;

import com.xjy.common.core.page.TableDataInfo;
import com.xjy.common.utils.poi.ExcelUtil;
import com.xjy.system.domain.bo.SysMaterialStatusAddBo;
import com.xjy.system.domain.bo.SysMaterialStatusEditBo;
import com.xjy.system.domain.bo.SysMaterialStatusQueryBo;
import com.xjy.system.domain.vo.SysMaterialStatusVo;
import lombok.RequiredArgsConstructor;
import javax.validation.constraints.*;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.xjy.common.annotation.RepeatSubmit;
import com.xjy.common.annotation.Log;
import com.xjy.common.core.controller.BaseController;
import com.xjy.common.core.domain.AjaxResult;
import com.xjy.common.enums.BusinessType;
import com.xjy.system.service.ISysMaterialStatusService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 物料状态信息Controller
 *
 * @author xjy
 * @date 2022-01-30
 */
@Api(value = "物料状态信息控制器", tags = {"物料状态信息管理"})
//@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/system/status")
public class SysMaterialStatusController extends BaseController {
	@Autowired
    private  ISysMaterialStatusService iSysMaterialStatusService;

    /**
     * 查询物料状态信息列表
     */
    @ApiOperation("查询物料状态信息列表")
    @PreAuthorize("@ss.hasPermi('system:status:list')")
    @GetMapping("/list")
    public TableDataInfo<SysMaterialStatusVo> list(@Validated SysMaterialStatusQueryBo bo) {
        return iSysMaterialStatusService.queryPageList(bo);
    }

    /**
     * 导出物料状态信息列表
     */
    @ApiOperation("导出物料状态信息列表")
    @PreAuthorize("@ss.hasPermi('system:status:export')")
    @Log(title = "物料状态信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<SysMaterialStatusVo> export(@Validated SysMaterialStatusQueryBo bo) {
        List<SysMaterialStatusVo> list = iSysMaterialStatusService.queryList(bo);
        ExcelUtil<SysMaterialStatusVo> util = new ExcelUtil<SysMaterialStatusVo>(SysMaterialStatusVo.class);
        return util.exportExcel(list, "物料状态信息");
    }

    /**
     * 获取物料状态信息详细信息
     */
    @ApiOperation("获取物料状态信息详细信息")
    @PreAuthorize("@ss.hasPermi('system:status:query')")
    @GetMapping("/{id}")
    public AjaxResult<SysMaterialStatusVo> getInfo(@NotNull(message = "主键不能为空")
                                                  @PathVariable("id") Long id) {
        return AjaxResult.success(iSysMaterialStatusService.queryById(id));
    }

    /**
     * 新增物料状态信息
     */
    @ApiOperation("新增物料状态信息")
    @PreAuthorize("@ss.hasPermi('system:status:add')")
    @Log(title = "物料状态信息", businessType = BusinessType.INSERT)
    @RepeatSubmit
    @PostMapping()
    public AjaxResult<Void> add(@Validated @RequestBody SysMaterialStatusAddBo bo) {
        return toAjax(iSysMaterialStatusService.insertByAddBo(bo) ? 1 : 0);
    }

    /**
     * 修改物料状态信息
     */
    @ApiOperation("修改物料状态信息")
    @PreAuthorize("@ss.hasPermi('system:status:edit')")
    @Log(title = "物料状态信息", businessType = BusinessType.UPDATE)
    @RepeatSubmit
    @PutMapping()
    public AjaxResult<Void> edit(@Validated @RequestBody SysMaterialStatusEditBo bo) {
        return toAjax(iSysMaterialStatusService.updateByEditBo(bo) ? 1 : 0);
    }

    /**
     * 删除物料状态信息
     */
    @ApiOperation("删除物料状态信息")
    @PreAuthorize("@ss.hasPermi('system:status:remove')")
    @Log(title = "物料状态信息" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult<Void> remove(@NotEmpty(message = "主键不能为空")
                                       @PathVariable Long[] ids) {
        return toAjax(iSysMaterialStatusService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
    }
}
